<?php

class mdistributor extends CI_Model {
    
        ########################################################################
        ####### DATA DISTRIBUTOR ##############
        ########################################################################
        
        function getDistributor(){
                $dblokal = $this->load->database("default", TRUE);
		
                $dblokal->select('*');
				$dblokal->where(array("istatus"=>1));
                $dblokal->from("t_mtr_distributor");
                $query = $dblokal->get();
                
                if( $query->num_rows() > 0 ) {
                        return $query->result();
                } else {
                        return array();
                }
        }
        
        function get($id = "")
        {    
                $dblokal  = $this->load->database("default", TRUE);
                if($id<>""){
                        $dblokal->where(array("distributor_id"=>$id));
                }
				$dblokal->where(array("istatus"=>1));
                $query = $dblokal->get("t_mtr_distributor");
                if( $query->num_rows() > 0 ) {
                        return $query->result();
                } else {
                        return array();
                }
	}
        
        
        #########################
        #########################
        
        public function getById( $id ) {
                #$id = intval( $id );
                
                $query = $this->db->where( 'id', $id )->limit( 1 )->get( 't_mtr_distributor' );
                
                if( $query->num_rows() > 0 ) {
                    return $query->row();
                } else {
                    return array();
                }
        }
        
        public function getAll() {
                //get all records from users table
                $query = $this->db->get( 't_mtr_distributor' );
                
                if( $query->num_rows() > 0 ) {
                    return $query->result();
                } else {
                    return array();
                }
        } //end getAll
        
        /*
		public function update() {
                $data = array(
                    'user_group_name' => $this->input->post( 'name', true ),
					'parent_id' => $this->input->post( 'parent', true ),
                    'having_stock' => $this->input->post( 'stock', true )
                );
                $this->db->update( 't_mtr_distributor', $data, array( 'distributor_id' => $this->input->post( 'id', true ) ) );
        }*/
        
        /*public function delete( $id ) {*/
                /*
                * Any non-digit character will be excluded after passing $id
                * from intval function. This is done for security reason.
                
                $id = intval( $id );
                $this->db->update( 't_mtr_distributor', array('istatus'=>0), array( 'user_group_id' => $id ) );
        } //end delete
				*/
    
} //end class